package com.gzu.ltms.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SaInterceptor(handle -> {
                    System.out.println("---------- Sa-Token 全局拦截器 -----------");
                    // 校验是否登录
                    StpUtil.checkLogin();
                }))
                // 拦截所有地址
                .addPathPatterns("/**")
                // 请求白名单
                .excludePathPatterns("/test/**"
                        , "/user/login");
    }
}
